/**
 * 服务端 API 代理模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	var ajax = require('mokit/ajax');
	var json = require('mokit/json');
	var app = require('mokit/app');
	var utils = require('mokit/utils');

	var getFullUrl = function(url) {
		var serviceUrl = app.config.serviceUri + url;
		var user = require('./User');
		var state = user.getState() || {};
		var token = state.token || state.mobileToken || '';
		serviceUrl += ($utils.contains(serviceUrl, '?') ? '&' : '?') + 'token=' + encodeURIComponent(token);
		return serviceUrl;
	};

	var self = {

		/**
		 * 用户 API
		 */
		user: {
			reg: function(regInfo, callback) {
				ajax.post({
					url: getFullUrl('user/mobile/reg'),
					data: {
						'userName': regInfo.account,
						'userPwd': regInfo.password,
						'userEmail': regInfo.email
					},
					callback: callback
				});
			},

			/**
			 * 登录
			 */
			login: function(loginInfo, callback) {
				ajax.post({
					url: getFullUrl('user/mobile/login'),
					data: {
						'userName': loginInfo.account,
						'userPwd': loginInfo.password
					},
					callback: callback
				});
			},

			/**
			 * 登出
			 */
			logout: function(callback) {
				ajax.post({
					url: getFullUrl(''),
					data: {
						'method': 'Logout'
					},
					callback: callback
				});
			}
		},
		
		//首页
		index: {		
			//获取轮播列表
			getList: function(callback) {
				ajax.get({
					url: getFullUrl('index/mobile/index'),
					contentType: 'application/json;charset=utf-8',
					callback: callback
				});
			},
		},
		
		//校友录 
		contact:{
			//获取校友列表
			getList: function(args, callback) {
				ajax.get({
					url: getFullUrl('friends/mobile/friendslist'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//添加分组
			addGroup: function(args, callback) {
				ajax.get({
					url: getFullUrl('friends/mobile/addgroup'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},			
			//删除分组
			delGroup: function(args, callback) {
				ajax.get({
					url: getFullUrl('friends/mobile/deletegroup'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//添加用户
			addUser: function(args, callback) {
				ajax.get({
					url: getFullUrl('friends/mobile/fridendadd'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//删除用户
			delUser: function(args, callback) {
				ajax.get({
					url: getFullUrl('接口待定'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
		},
		
		//项目
		project: {
			submit: function(projectInfo, callback) {
				projectInfo = utils.copy(projectInfo);
				ajax.post({
					url: getFullUrl('sendproject/mobile/dosend'),
					contentType: 'application/json;charset=utf-8',
					data: json.stringify(projectInfo),
					callback: callback
				});
			},
			//获取项目类别列表
			getCatList: function(callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/cargolist'),
					contentType: 'application/json;charset=utf-8',
					callback: callback
				});
			},
			//获取项目列表
			getProjectList: function(args, callback) {
				ajax.get({
					url: getFullUrl('projectmo/mobile/projectlist'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},		
			//获取项目详情
			getProjectInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('projectmo/mobile/tojointeam'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//加入项目
			join2project: function(args, callback) {
				ajax.get({
					url: getFullUrl('sendproject/mobile/competitive'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取职位详情
			getPosInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('projectmo/mobile/roleother'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},			
		},

		//服务商
		provider: {
			//获取服务商列表
			getList: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/findservice'),
					data: args,
					callback: callback
				});
			},
			//获取服务商详情
			getInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/servicedetail'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//推荐服务商
			tuijian: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/tuijian'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//关注服务商
			attention: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/doattention'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},			
			//邀请加入团队
			joinTeam: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/askjoin'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},				
			//获取作品墙列表
			getWorksWallList: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/worklist'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取作品墙详情
			getWorksWallInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/workdetail'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取作品墙留言
			getWorksWallGuess: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/comments'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			}
		},	

		//作品
		works: {
			//获取作品列表
			getList: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/findWorkList'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},		
			//获取作品详情
			getInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/workdetail'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//收藏作品
			collect: function(args, callback) {
				ajax.get({
					url: getFullUrl('service/mobile/collectforwork'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			}
		},
		
		//文章
		article: {
			//获取文章列表
			getList: function(args, callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/sharelist'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取文章详情
			getInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/sharedetail'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取热门文章列表
			getHotList: function(args, callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/hotlist'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
		},

		//问答
		faq: {
			//获取问答列表
			getList: function(args, callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/problem'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},
			//获取问答详情
			getInfo: function(args, callback) {
				ajax.get({
					url: getFullUrl('sharemobile/mobile/problemInfo'),
					contentType: 'application/json;charset=utf-8',
					data: args,
					callback: callback
				});
			},			
		},


		//个人中心
		ucenter: {
			//1、个人资料
			info:{
				//获取详情
				getInfo: function(args, callback) {
					ajax.get({
						url: getFullUrl('owercenter/mobile/centerinfo'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},
			},
			
			//2、个人财务
			money: {
				//获取详情
				getInfo: function(args, callback) {
					ajax.get({
						url: getFullUrl('owermoney/mobile/owermoney'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},
			},

			//3、项目
			project: {
				//获取项目列表
				getList: function(args, callback) {
					ajax.get({
						url: getFullUrl('owercenter/mobile/applyproject'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},			
				//获取项目详情
				getInfo: function(args, callback) {
					ajax.get({
						url: getFullUrl('owercommunity/mobile/projectinfo'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},
				//子任务
				subtask: {
					//获取子任务列表
					getList: function(args, callback) {
						ajax.get({
							url: getFullUrl('owercommunity/mobile/ziprojectlist'),
							contentType: 'application/json;charset=utf-8',
							data: args,
							callback: callback
						});
					},
					//获取子任务详情
					getInfo: function(args, callback) {
						ajax.get({
							url: getFullUrl('owercommunity/mobile/ziprojectdetail'),
							contentType: 'application/json;charset=utf-8',
							data: args,
							callback: callback
						});
					}
				},
				//项目成员
				member: {
					getList: function(args, callback){
						ajax.get({
							url: getFullUrl('owercommunity/mobile/touserlist'),
							contentType: 'application/json;charset=utf-8',
							data: args,
							callback: callback
						});						
					}				
				},				
				//邀请成员
				inviteMember: function(args, callback){
					ajax.get({
						url: getFullUrl('owercommunity/mobile/askpeople'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},
				
			},
			
			//4、5、我的社区
			community: {
				//获取详情
				getInfo: function(args, callback) {
					ajax.get({
						url: getFullUrl('owercommunity/mobile/mycommunity'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},				
			},

			//6、我的日程
			schedule: {
				//获取列表
				getList: function(args, callback) {
					ajax.get({
						url: getFullUrl('myschedule/mobile/myschedulelist'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},
				//添加日程
				add: function(args, callback) {
					ajax.get({
						url: getFullUrl('myschedule/mobile/doaddschedule'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});
				},				
			},
			
			//7、我的消息
			message: {
				//获取列表
				getList:function(args,callback){
					ajax.get({
						url: getFullUrl('owercenter/mobile/mymessagelist'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});					
				}
			},
			
			//8、我的收藏
			collect: {
				//获取列表
				getList:function(args,callback){
					ajax.get({
						url: getFullUrl('owercenter/mobile/mycollectlist'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});					
				}
			},
			
			//9、系统设置
			setting: {
				//获取信息
				getInfo:function(args,callback){
					ajax.get({
						url: getFullUrl('mymessage/mobile/myinfo'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});					
				},			
				//更新信息
				upInfo:function(args,callback){
					ajax.get({
						url: getFullUrl('mymessage/mobile/updatemyinfo'),
						contentType: 'application/json;charset=utf-8',
						data: args,
						callback: callback
					});					
				}
			},
			
		},

		//点赞
		sayGood: function(args, callback) {
			ajax.get({
				url: getFullUrl('sharemobile/mobile/good'),
				contentType: 'application/json;charset=utf-8',
				data: args,
				callback: callback
			});
		},

		//添加收藏
		addCollection: function(args, callback) {
			ajax.get({
				url: getFullUrl('sharemobile/mobile/collectionAdd'),
				contentType: 'application/json;charset=utf-8',
				data: args,
				callback: callback
			});
		},

		//获取留言列表
		getCommentList: function(args, callback) {
			ajax.get({
				url: getFullUrl('comment/mobile/list'),
				contentType: 'application/json;charset=utf-8',
				data: args,
				callback: callback
			});
		},
		
	};

	/**
	 * 添加数据过滤器
	 */
	/*ajax.addDataFilter({
		send: function(data) {
			if (utils.isNull(data)) return data;
			var user = require('./User');
			var state = user.getState() || {};
			data.token = state.token || state.mobileToken || '';
			return data;
		}
	});*/

	return self;
});